﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '支持金额(元)', name: 'Amount', width: "7%", sortable: false, align: 'left' },
                    { display: '创建时间', name: 'AddTime', width: "7%", sortable: false, align: 'left' },
                    { display: '支付时间', name: 'PayTime', width: "7%", sortable: false, align: 'left' },
                    { display: '订单编号', name: 'SerialNumber', width: "7%", sortable: false, align: 'left' },
                    { display: '联系人', name: 'Contacts', width: "7%", sortable: false, align: 'left' },
                    { display: '联系号码', name: 'ContactNumber', width: "7%", sortable: false, align: 'left' },
                    { display: '备注', name: 'Remark', width: "7%", sortable: false, align: 'left' },
                    { display: '支付状态', name: 'PayStatus', width: "7%", sortable: false, align: 'left', process: PayStatus },
                    { display: '操作', name: 'Id', width: "13%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);

        function processOp(value, cell) {
            var ops = [];
            if (cell[8] == "1") {
                ops.push("&nbsp;<a title='查询订单' href='javascript:;'  onclick=\"util.QueryFund('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>查询订单</a>");
            } else {
                ops.push("&nbsp;<a title='退款' href='javascript:;'  onclick=\"util.ReFund('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>退款</a>");
            }
            return ops.join("");
        }
        //支付状态
        function PayStatus(value, cell) {
            if (value == 0) {
                return '等待付款';
            } else if (value == 1) {
                return '付款成功';
            } else if (value == 2) {
                return '付款失败';
            } else if (value == 3) {
                return '过期';
            } else if (value == 4) {
                return '撤销成功';
            } else if (value == 5) {
                return '退款中';
            } else if (value == 6) {
                return '退款成功';
            } else if (value == 7) {
                return '退款失败';
            } else if (value == 8) {
                return '部分退款成功';
            } else if (value == 9) {
                return '已收货';
            } else if (value == 10) {
                return '交易关闭';
            } else {
                return '交易完成';
            }
        };
        $("#formProOrderList").submit(function () {
            xjgrid.Query(this);
            return false;
        });

        $("#btnSearch").click(function () {
            $("#formProOrderList").submit();
        });

        util.QueryFund = function (orderid) {
            window.location.href = options.QueryfundUrl + "?projectOrderId=" + orderid;
        };

        util.ReFund = function (orderid) {
            if (!confirm("您确定退款吗？")) {
                return false;
            }
            $.post(options.RefundUrl, { projectOrderId: orderid },
                  function (res) {
                      if (res.Status > 0) {
                          alert(res.message);
                          alert(res.Message);
                          alert("操作成功");
                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);